package com.hook3.pianke.view;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

import com.hook3.pianke.MainActivity;
import com.hook3.pianke.R;
import com.hook3.pianke.view.utils.CacheUtils;

/**
 * Created by 柴孟鑫 on 2015/12/7.
 */
public class SplashActivity extends Activity{
   public static final String IS_START_MAIN = "is_start_main";
    private RelativeLayout fl_splash;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        fl_splash = (RelativeLayout) findViewById(R.id.fl_splash);
        startAnimation();

    }

    /**
     * 动画效果
     */
    private void startAnimation() {
        ScaleAnimation sa = new ScaleAnimation(1,1.1f,1,1.1f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
        sa.setDuration(3000);
        sa.setFillAfter(true);
        fl_splash.startAnimation(sa);
        sa.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            /**
             * 动画结束监听
             * @param animation
             */
            @Override
            public void onAnimationEnd(Animation animation) {
                boolean isStartMain = CacheUtils.getBoolean(SplashActivity.this,
                        IS_START_MAIN);
                Intent intent;

                if (isStartMain) {
                    intent = new Intent(SplashActivity.this, MainActivity.class);

                } else {
                    intent = new Intent(SplashActivity.this, GuideActivity.class);


                }
                startActivity(intent);
                finish();

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

    }
}
